<template>
  <a-modal :width="1080" title="分佣配置" v-model="visible" :footer="null">
    <a-card title="佣金配置" size="small" style="margin-bottom:15px;">
      <div>商品分销比例： {{ rate }} %</div>
      <div>最低折扣： {{ discount }} 折</div>
      <div class="table-page-search-wrapper">
        <div style="display:flex;line-height:42px;">
          <div style="flex:1;text-align:center;">-</div>
          <div style="flex:1;text-align:center;" v-for="(item,index) in dataSource" :key="index">
            {{ item.name }}
          </div>
        </div>

        <div style="display:flex;line-height:42px;">
          <div style="flex:1;text-align:center;">拿货折扣</div>
          <div style="flex:1;text-align:center;"
               v-for="(item2,index2) in rangeDiscountList" :key="index2">
            <a-input-number v-model="rangeDiscountList[index2].discount" :step="1"
                            :precision="2"/>
            <span>折</span>
          </div>
        </div>
        <a-row :gutter="24">
          <a-col :xl="24" :lg="24" :md="24" :sm="24" style="text-align:center;padding-top:20px;">
            <a-button type="primary" @click="saveConfig">保存</a-button>
          </a-col>
        </a-row>
      </div>
    </a-card>

  </a-modal>
</template>

<script>

import {getAction, postAction, putAction} from "@api/manage";
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/MyJeecgListMixin'


export default {
  name: 'GmsRangeInfo',
  components: {},
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      description: '分佣配置',
      dataSource: [],
      rangeDiscountList: [],
      itemId: "",
      itemType: 0,
      visible: false,
      discount: 10,
      rate: 0,
      goodId: null,
      url: {
        handList: "/mallPlus/hmsHandConfig/list",
        edit: "/good/gmsDiscount/edit",
        editPt: "/pt/ptmsDiscount/edit",
        editMs: "/ms/msmsDiscount/edit",
        // editYy: "/yy/yymsDiscount/edit",
        query: "/good/gmsDiscount/queryById",
        queryPt: "/pt/ptmsDiscount/queryById",
        queryMs: "/ms/msmsDiscount/queryById",
        // queryYy: "/yy/yymsDiscount/queryById",
      },
    }

  },

  methods: {
    open() {
      this.loadData()
    },
    saveConfig() {
      let that = this
      let url = this.url.edit
      let formData = {
        itemId: this.itemId,
        itemType: this.itemType,
        discountConfig: JSON.stringify({list: this.rangeDiscountList})
      }

      if (this.itemType == 2) {
        url = this.url.editMs
      } else if (this.itemType == 3) {
        url = this.url.editPt
      }
      // else if (this.itemType == 5) {
      //   url = this.url.editYy
      // }
      postAction(url, formData).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    loadData() {
      getAction(this.url.handList).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
        }
      })
      this.getDiscount()
    },
    getDiscount() {
      let url = this.url.query;
      if (this.itemType == 2) {
        url = this.url.queryMs
      } else if (this.itemType == 3) {
        url = this.url.queryPt
      }
      // else if (this.itemType == 5) {
      //   url = this.url.queryYy
      // }
      getAction(url, {itemId: this.itemId, itemType: this.itemType}).then((res) => {
        if (res.success) {
          this.rangeDiscountList = JSON.parse(res.result.discountConfig).list
          this.discount = res.result.discount
          this.rate = res.result.rate
        }
        console.log(this.rangeDiscountList)
      })
    },
  }


}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
